USE [wdms]
GO

-- =============================================
-- Author     :		Lohith Ram D V
-- Create date:         08/mar/2011
-- =============================================

create procedure sp_ModifyUserRole (
	@par_userupdateid int,
	@par_username nchar(100))
AS
BEGIN
	DECLARE @roleid int
	SELECT @roleid = (SELECT [User1].[role_id]
	FROM [User1]
	WHERE [User1].[user1_id]=@par_userupdateid)
	
	if(@roleid = 3)
	BEGIN
		SELECT @roleid = (SELECT [User1].[requested_position]
		FROM [User1]
		WHERE [User1].[user1_name]=@par_username)
	
		UPDATE [User1] 
		SET [User1].[role_id]=@roleid
		WHERE [User1].[user1_name]=@par_username
		RETURN 1;
	END
	ELSE
		RETURN 0;
END
